package com.unlcn.erp.hyc.interfaces.api.controller;

import cn.huiyunche.commons.domain.ResultDTO;
import cn.huiyunche.commons.exception.BusinessException;
import com.unlcn.erp.hyc.interfaces.backend.service.CallOrderByHYCService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by zhiche024 on 2017/9/5.
 */
@Controller
@RequestMapping("/callOrderByHYC")
public class CallOrderByHYCController {
    private static final Logger LOGGER = LoggerFactory.getLogger(CallOrderByHYCController.class);

    @Autowired
    private CallOrderByHYCService callOrderByHYCService;

    @RequestMapping(value = "/saveOrderByHYC" ,method = RequestMethod.GET)
    @ResponseBody
    public void saveOrderByHYC(){
        LOGGER.info("CallOrderByHYCController.saveOrderByHYC param:{}.");
        ResultDTO<Object> result = new ResultDTO<Object>(true, null, "查询成功");
        try{
            callOrderByHYCService.getOrderCodes();
        }catch (Exception e){
            LOGGER.error("CallOrderByHYCController.saveOrderByHYC error: {}", e);
            throw new BusinessException(e.getMessage());
        }
    }

    @RequestMapping(value = "/saveOrderByCode", method = RequestMethod.GET)
    @ResponseBody
    public ResultDTO<Object> saveOrderByCode(String orderCode){
        LOGGER.info("CallOrderByHYCController.saveOrderByCode param:{}.");
        ResultDTO<Object> result = new ResultDTO<Object>(true, null, "订单保存成功");
        try{
            callOrderByHYCService.saveOrderByCode(orderCode);
        }catch (Exception e){
            LOGGER.error("CallOrderByHYCController.saveOrderByCode error: {}", e);
            result.setSuccess(false);
            result.setMessage("订单保存失败");
            throw new BusinessException(e.getMessage());
        }
        return result;
    }


}
